<?php
namespace app\common\logic;
class Qcode
{
    public function createCode($content,$logo,$filename){
        $qrCode = new \Endroid\QrCode\src\QrCode($content);
        //设置前景色
        $qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' =>0, 'a' => 0]);
        //设置背景色
        $qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0]);
        //设置二维码大小
        $qrCode->setSize(200);
        $qrCode->setPadding(20);
        if ($logo ==true){
            //添加logo
            $logo=dirname(__DIR__).'/../../public/static/logo/code1.jpg';
            $qrCode->setLogo($logo);
            //设置logo大小
            $qrCode->setLogoSize(40);
            //二维码描述
//            $qrCode->setLabel($logoSrc);
//            $qrCode->setLabelFontSize(14);
//            $qrCode->setLabelHalign(100);
        }

        //绘制二维码边框
        // $qrCode->setDrawBorder(true);
        //获取二维码数据
        $img= $qrCode->getDataUri();
        if ($filename)
            $qrCode -> save($filename);
        return $img;
    }
}